﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business
{
    public partial class OutInspection : Form
    {
        public MainForm m_mainform;
        private CheckBox[] cchebox;
        public int iliushuihao;
        public OutInspection(int iDET)
        {
            InitializeComponent();
            iliushuihao = iDET;
            cchebox = new CheckBox[50] { checkBox1, checkBox2, checkBox3, checkBox4, checkBox5, checkBox6, checkBox7, checkBox8, checkBox9, checkBox10
                ,checkBox11, checkBox12, checkBox13, checkBox14, checkBox15, checkBox16, checkBox17, checkBox18, checkBox19, checkBox20
                ,checkBox21, checkBox22, checkBox23, checkBox24, checkBox25, checkBox26, checkBox27, checkBox28, checkBox29, checkBox30
                ,checkBox31, checkBox32, checkBox33, checkBox34, checkBox35, checkBox36, checkBox37, checkBox38, checkBox39, checkBox40
                ,checkBox41, checkBox42, checkBox43, checkBox44, checkBox45, checkBox46, checkBox47, checkBox48, checkBox49, checkBox50};
            getwjxm();
        }
        public void getwjxm()
        {
            
            Query objquery = new Query();
            string ssqlex = "";
            ssqlex = string.Format(@"select * from LWHQXM where DETECT_ID={0} ", iliushuihao);
            DataTable dt = objquery.GetTable(ssqlex);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
               
                string swjxm = "";
                swjxm = string.Format(@"{0},{1},{2}", dt.Rows[i]["wgjcxm"].ToString().Trim(), dt.Rows[i]["dtdpjyxm"].ToString().Trim(), dt.Rows[i]["dpjyxm"].ToString().Trim());
                if (swjxm.Contains("01"))
                {
                    cchebox[0].Checked = true;
                }
                else
                {
                    cchebox[0].Checked = false;
                }
                if (swjxm.Contains("02"))
                {
                    cchebox[1].Checked = true;
                }
                else
                {
                    cchebox[1].Checked = false;
                }
                if (swjxm.Contains("03"))
                {
                    cchebox[2].Checked = true;
                }
                else
                {
                    cchebox[2].Checked = false;
                }
                if (swjxm.Contains("04"))
                {
                    cchebox[3].Checked = true;
                }
                else
                {
                    cchebox[3].Checked = false;
                }
                if (swjxm.Contains("05"))
                {
                    cchebox[4].Checked = true;
                }
                else
                {
                    cchebox[4].Checked = false;
                }
                if (swjxm.Contains("06"))
                {
                    cchebox[5].Checked = true;
                }
                else
                {
                    cchebox[5].Checked = false;
                }
                if (swjxm.Contains("07"))
                {
                    cchebox[6].Checked = true;
                }
                else
                {
                    cchebox[6].Checked = false;
                }
                if (swjxm.Contains("08"))
                {
                    cchebox[7].Checked = true;
                }
                else
                {
                    cchebox[7].Checked = false;
                }
                if (swjxm.Contains("09"))
                {
                    cchebox[8].Checked = true;
                }
                else
                {
                    cchebox[8].Checked = false;
                }
                for (int j = 9; j < 50; j++)
                {
                    if (swjxm.Contains(string.Format(@"{0}", j + 1)))
                    {
                        cchebox[j].Checked = true;
                    }
                    else
                    {
                        cchebox[j].Checked = false;
                    }
                    
                }
               
            }
        }

        private void baocun_Click(object sender, EventArgs e)
        {
            
         





        }

        private void but_save_Click(object sender, EventArgs e)
        {
           
            string sbhgx1 = "";
            string sbhgx2 = "";
            string sbhgx3 = "";
            string sbhgx4 = "";
            string sbhgx5 = "";
            string sbhgx6 = "";
            string sbhgx7 = "";

            for (int i = 0; i < 5; i++)//1
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx1 != "")
                    {
                        sbhgx1 = sbhgx1 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx1 = cchebox[i].Text + "不符合要求";
                    }
 
                }
            }

            for (int i = 6; i < 16; i++)//2
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx2 != "")
                    {
                        sbhgx2 = sbhgx2 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx2 = cchebox[i].Text + "不符合要求";
                    }

                }
            }
            for (int i = 16; i < 22; i++)//3
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx3 != "")
                    {
                        sbhgx3 = sbhgx3 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx3 = cchebox[i].Text + "不符合要求";
                    }

                }
            }
            for (int i = 22; i < 41; i++)//4
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx4 != "")
                    {
                        sbhgx4 = sbhgx4 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx4 = cchebox[i].Text + "不符合要求";
                    }

                }
            }
            for (int i = 5; i < 6; i++)//5
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx5 != "")
                    {
                        sbhgx5 = sbhgx5 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx5 = cchebox[i].Text + "不符合要求";
                    }

                }
            }
            for (int i = 41; i < 45; i++)//6
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx6 != "")
                    {
                        sbhgx6 = sbhgx6 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx6 = cchebox[i].Text + "不符合要求";
                    }

                }
            }
            for (int i = 45; i < 50; i++)//7
            {
                if (cchebox[i].Checked)
                {
                    if (sbhgx7 != "")
                    {
                        sbhgx7 = sbhgx7 + " " + cchebox[i].Text + "不符合要求";
                    }
                    else
                    {
                        sbhgx7 = cchebox[i].Text + "不符合要求";
                    }

                }
            }


           // WaiJianPanDing
            Query mquery = new Query();
            string sql;
            sql = string.Format(@"Select * from WaiJianPanDing Where DETECT_ID={0}",iliushuihao);
            DataTable dt = mquery.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update  WaiJianPanDing set   WJPD_1='{0}',
                                                        WJPD_2='{1}',
                                                        WJPD_3='{2}',
                                                        WJPD_4='{3}',
                                                        WJPD_5='{4}',
                                                        WJPD_6='{5}',
                                                        WJPD_7='{6}'
                                                        Where DETECT_ID={7}",
                                                        sbhgx1,
                                                        sbhgx2,
                                                        sbhgx3,
                                                        sbhgx4,
                                                        sbhgx5,
                                                        sbhgx6,
                                                        sbhgx7,
                                                        iliushuihao);
                mquery.UpdateTable(sql);
                //保存操作日记
                m_mainform.savecaozuoriji(sql, "更新", "业务系统", "更新外检项目");
                //判断是否核心功能
                if (m_mainform.shxgn.Contains("外检项目定义增加"))
                {
                    m_mainform.baocunhxrj("外检项目定义增加", string.Format("外检项目定义增加"), "写入");// 核心功能日记  日记内容
                }
            }
        }

        private void OutInspection_Load(object sender, EventArgs e)
        {
            //判断是否民警
            if (m_mainform.sfjy.Contains("外检项目定义增加"))
            {
                if (!m_mainform.SFMJ.Contains("是"))
                {
                    but_save.Enabled = false;
                }
            }
        }
    }
}
